<?php include $this->templateDir . 'common/header.php'; ?>
<body>
<style type="text/css">
    /* 分页样式 */
    .grace-pager{float:left;}
    .grace-pager a{display:block; background:#F5F5F5; padding:0px 10px; height:25px; line-height:25px; float:left; margin:3px; border-radius:2px;}
    .grace-pager a:hover{background:#2F4056; text-decoration:none; color:#FFF;}
    .grace-pager .grace-current{background:#5FB878 !important; color:#FFF !important;}
    #search .layui-input,#search .layui-unselect{height: 30px!important;}
</style>
<div class="yadmin-body animated fadeIn">
    <div class="layui-card" >
        <div class="layui-card-header" id="search">
            <form class="layui-form yadmin-search-area input " style="min-width: 500px;display: inline;overflow: hidden;width: 500px;height: 40px;line-height: 40px;" >
                    <div style="float: left;height: 40px;">
                        <button class="layui-btn layui-btn-sm"  onclick="add()">添加管理员</button>
                    </div>
                    <div style="float: left;height: 40px;">
                        <label for="email" class="layui-form-label">邮箱</label>
                        <div class="layui-input-inline">
                            <input type="text" name="email" autocomplete="off"
                                   id="email" class="layui-input ">
                        </div>
                    </div>
                    <div style="float: left; ">
                    <label for="status" class="layui-form-label">角色</label>
                    <div class="layui-input-inline">
                        <select name="role" id="role">
                            <option value="-1">请选择</option>
                            <?php
                            foreach ($this->roles as $key => $value) {
                                echo " <option value='".$value['role_id']."'>".$value['role_name']."</option>";
                            }
                            ?>
                        </select>
                    </div>
                    <button lay-submit="" lay-filter="search" class="layui-btn layui-btn-sm layui-btn-primary table-action">
                        <i class="layui-icon layui-icon-search"></i>
                    </button>
                    </div>

            </form>
        </div>
        <div class="layui-card-body">
            <table class="layui-table" >
                <colgroup>
                    <col style="min-width: 100px">
                    <col style="min-width: 100px">
                    <col style="min-width: 100px">
                </colgroup>
                <thead>
                <tr>
                    <th>序号ID</th>
                    <th>用户名</th>
                    <th>角色归属</th>
                    <th>登录邮箱</th>
                    <th>登录IP</th>
                    <th>创建时间</th>
                    <th>登陆时间</th>
                    <th>操&nbsp;&nbsp;&nbsp;&nbsp;作</th>
                </tr>
                </thead>
                <tbody>
                <?php foreach ($this->data[0] as $rows) { ?>
                    <tr>
                        <td><?php echo $rows['id'];?></td>
                        <td><?php echo $rows['manager_uname'];?></td>
                        <td><?php echo $rows['role_name'];?></td>
                        <td><?php echo $rows['email'];?></td>
                        <td><?php echo $rows['manager_ip'];?></td>
                        <td><?php echo date("Y-m-d H:i:s",$rows['create_time']) ;?></td>
                        <td><?php echo date("Y-m-d H:i:s",$rows['manager_login_time']);?></td>
                        <td>
                            <button class="layui-btn layui-btn-sm" onclick="edit(<?php echo $rows['id']?>)"><i class="layui-icon layui-icon-edit" title="编辑"></i> 编辑</button>
                            <button class="layui-btn layui-btn-sm" onclick="del(<?php echo $rows['id']?>)"><i class="layui-icon layui-icon-delete" title="删除"></i> 删除 </button>
                        </td>
                    </tr>

                <?php } ?>
                </tbody>
            </table>
            <div style="width:100%; ">
                <div class="grace-pager">
                    <a href="<?php echo $this->data[1]->firstPage;?>">首页</a>
                    <a href="<?php echo $this->data[1]->prePage;?>">上一页</a>
                    <?php
                    foreach($this->data[1]->listPage as $k => $v){
                        if($k == $this->data[1]->currentPage){
                            echo '<a href="'.$v.'" class="grace-current">'.$k.'</a>';
                        }else{
                            echo '<a href="'.$v.'">'.$k.'</a>';
                        }
                    }
                    ?>
                    <a href="<?php echo $this->data[1]->nextPage;?>">下一页</a>
                    <a href="<?php echo $this->data[1]->lastPage;?>">尾页</a>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
</html>
<script>
    layui.use(['table', 'element', 'form' ],function () {
        var table = layui.table;
         $ = layui.$;
         form = layui.form;
        element = layui.element;

        form.on('submit(search)', function (form) {
             var email = form.field.email;
            role = form.field.role;
             if(email == ''){
                 email = 0;
             }
            window.location.href = "<?php echo PG_SROOT;?>manage/index/"+email+'/'+role;
            return false;
        });
    });
    // 添加
    function add() {
        layer.open({
            content: "<?php echo u('manage','add')?>",
            title: "新增后台用户",
            area: ['40%', '60%'],
            type: 2,
            maxmin: true,
            shadeClose: true
        });
    }

    // 编辑
    function edit(id) {
        //右侧抽屉弹出编辑框
        layer.open({
            type    : 2,        //0：信息框，默认  1：页面层  2：iframe层 3：加载层 4：tips层
            offset  : 'rb',     //右侧抽屉效果
            title   : '编辑信息',
            anim    : Math.ceil(Math.random()*5),// anim 特效 0-平滑放大 1-从上掉落 2-从底部往上滑入 3-从左滑入 4-从左翻转 5-渐显 5-抖动
            area    : ['50%', '100%'],// 第一个参数宽度，第二个参数高度
            content : '<?php echo PG_SROOT?>manage/edit/' + id,
            maxmin  : true,         //有最大最小按钮
            shadeClose: true      //开启遮罩关闭
        });
    }

    // 删除
    function del(id) {
        layer.confirm("删除后无法恢复，确定删除用户吗?", {icon: 3, title: '提示：删除用户 '},
            function (index) {
                //关闭窗口
                layer.close(index);
                //后台真实删除
                $.ajax({
                    url:"<?php echo u('manage','del')?>"
                    ,dataType:"json"
                    ,type:"post"
                    ,data:{'id':id}
                    ,success:function(res){
                        if(res.status == "ok"){
                            parent.layer.msg(res.data, {icon: 6,time:1000},function () {
                                window.parent.location.reload();
                            });
                        }else{
                            layer.msg(res.data,{icon:7});
                        }
                    }
                });
            }, function (index) {
                layer.close(index);
            }
        );
    }
</script>